#编写时间:2022-10-24
#编写人:付学瑞
import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import*
from selenium.webdriver.support.select import Select
testCase="DBshop011_商品管理管理商品添加商品"
shangpin="苹果XR"

# 1.点击添加商品按钮，商品名称填写“苹果XR”,本店价格“7999”，商品类型“虚拟商品”。
firefox=openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)
DBshopEnterMenu2(firefox,"商品管理","管理商品")
# 2.点击“保存商品”按钮，后台保存成功添加的商品。
# 查看商品总数
str1=firefox.find_element_by_xpath("//div[@style='height: 30px; border-bottom: 4px solid #DFDFDF;']").text
l="商品数："
r="\)"
num1=reGetString(str1,l,r)
print(num1)
firefox.find_element_by_link_text("添加商品").click()
firefox.find_element_by_id("goods_name").send_keys("苹果XR")
firefox.find_element_by_id("goods_shop_price").send_keys("7999")
# 处理下拉框
select=firefox.find_element_by_id("goods_type")
s=Select(select)
s.select_by_visible_text("虚拟商品")
# 点击保存按钮
firefox.find_element_by_xpath("//button[text()=' 保存商品']").click()
str2=firefox.find_element_by_xpath("//div[@style='height: 30px; border-bottom: 4px solid #DFDFDF;']").text
l="商品数："
r="\)"
num2=reGetString(str2,l,r)
print(num2)
try:
    if int(num2)==int(num1)+1:
        writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()
